package com.training.web.controller.comtent;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.training.common.annotation.Log;
import com.training.common.core.controller.BaseController;
import com.training.common.core.domain.AjaxResult;
import com.training.common.enums.BusinessType;
import com.training.content.domain.CompanyInfo;
import com.training.content.service.ICompanyInfoService;
import com.training.common.utils.poi.ExcelUtil;
import com.training.common.core.page.TableDataInfo;

/**
 * 公司信息Controller
 * @author training
 * @date 2021-10-24
 */

@RestController
@RequestMapping("/company/info")
public class CompanyInfoController extends BaseController
{
    @Autowired
    private ICompanyInfoService companyInfoService;

    /**
     * 查询公司信息列表
     */
    @PreAuthorize("@ss.hasPermi('company:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyInfo companyInfo)
    {
        startPage();
        List<CompanyInfo> list = companyInfoService.selectCompanyInfoList(companyInfo);
        return getDataTable(list);
    }

    /**
     * 导出公司信息列表
     */
    @PreAuthorize("@ss.hasPermi('company:info:export')")
    @Log(title = "公司信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyInfo companyInfo)
    {
        List<CompanyInfo> list = companyInfoService.selectCompanyInfoList(companyInfo);
        ExcelUtil<CompanyInfo> util = new ExcelUtil<>(CompanyInfo.class);
        return util.exportExcel(list, "公司信息数据");
    }

    /**
     * 获取公司信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:info:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId)
    {
        return AjaxResult.success(companyInfoService.selectCompanyInfoByCompanyId(companyId));
    }

    /**
     * 新增公司信息
     */
    @PreAuthorize("@ss.hasPermi('company:info:add')")
    @Log(title = "公司信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyInfo companyInfo)
    {
        return toAjax(companyInfoService.insertCompanyInfo(companyInfo));
    }

    /**
     * 修改公司信息
     */
    @PreAuthorize("@ss.hasPermi('company:info:edit')")
    @Log(title = "公司信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyInfo companyInfo)
    {
        return toAjax(companyInfoService.updateCompanyInfo(companyInfo));
    }

    /**
     * 删除公司信息
     */
    @PreAuthorize("@ss.hasPermi('company:info:remove')")
    @Log(title = "公司信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds)
    {
        return toAjax(companyInfoService.deleteCompanyInfoByCompanyIds(companyIds));
    }
}
